package org.example.game.history;

import java.util.HashMap;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/06/16 10:36
 */
public class Solution100304 {

    public static void main(String[] args) {
        Solution100304 solution100304 = new Solution100304();
        System.out.println(solution100304.countCompleteDayPairs(new int[]{72,48,24,3}));
    }

    public long countCompleteDayPairs(int[] hours) {
        //数字存在两种组合方式， 一种是 24的余数， 另外一种是 非24余数
        //24的余数， 任意两个组合都可以满足条件
        //非24话，可以先取模24

        HashMap<Integer, Long> hourCountMap = new HashMap<>();

        for (int i = 0; i < hours.length; i++) {
            int hour = hours[i] % 24;
            hourCountMap.putIfAbsent(hour, 0L);
            hourCountMap.put(hour, hourCountMap.get(hour) + 1);
        }

        // dayM[i] == 0 表示整天 i<j 所以两个数字，只能计算一次
        long sum = 0;
        for(int i=0;i<13;i++){
            Long count = hourCountMap.get(i);
            if(count == null){
                continue;
            }
            if(i == 0 || i == 12){
                if(count > 1){
                    sum += (count * (count - 1))/2;
                }
            }else {
                Long leftCount = hourCountMap.get(24-i);
                if(leftCount == null){
                    continue;
                }
                if(count > 0 && leftCount >0){
                    sum += count*leftCount;
                }
            }
        }
        return sum;
    }

}
